package com.hqyj.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hqyj.dao.CourceMapper;
import com.hqyj.pojo.Cource;
import com.hqyj.pojo.Department;
import com.hqyj.service.CourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p></p>
 *
 * @author : zlf
 * @date : 2020-09-02 20:06
 **/
@Service
public class CourceServcieImpl implements CourceService {
    @Autowired
    CourceMapper courceMapper;
    @Override
    public HashMap<String, Object> selectDnameAndCname(Cource cource) {
        HashMap<String,Object> map = new HashMap<>();
        PageHelper.startPage(cource.getPage(),cource.getRow());
        List<Cource> courceList = courceMapper.selectDnameAndCname(cource);
        PageInfo<Cource> pageInfo = new PageInfo<Cource>(courceList);
        List<Cource> list = pageInfo.getList();
        map.put("total",pageInfo.getTotal());
        map.put("pages",pageInfo.getPages());
        map.put("endPage",pageInfo.getNavigateLastPage());
        map.put("curPage",cource.getPage());
        map.put("data",courceList);
        return map;
    }

    @Override
    public HashMap<String, Object> courceAdd(Cource cource) {

        HashMap<String,Object> map = new HashMap<>();
        System.out.println(cource.toString());
        if (courceMapper.courceAdd(cource)>0)
        {
            map.put("info","增加成功");
        }else {
            map.put("info","增加失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> courceUpdat(Cource cource) {
        HashMap<String,Object> map = new HashMap<>();
        System.out.println(cource.toString()+"233333");
        if (courceMapper.courceUpdate(cource)>0)
        {
            map.put("info","修改成功");
        }else {
            map.put("info","修改失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> courceDel(Cource cource) {
        HashMap<String,Object> map = new HashMap<>();
        if (courceMapper.courceDel(cource)>0)
        {
            map.put("info","删除成功");
        }else {
            map.put("info","删除失败");
        }
        return map;
    }
}
